<template>
   <div class="withdraw-risk">
     <h3>提现风控设置说明</h3>
     <p class="tips">当提现的用户达到以下配置的条件后，则此笔提现自动进入，异常提现界面，需要风控人员进行审核</p>
     <p class="tips">这里的提现设置为全局设置，若“风控管理-会员提现风控”没有设置到的层级都会按照这里的提现风控流程进行，若已经设置了层级的风控，则按照层级风控流程进行</p>
    <el-form :inline="true"
             ref="strategyForm"
             :rules="strategyRule"
             label-width="150px"
             :disabled="loading"
             :model="form" class="demo-form-inline">
              <!-- <el-row>
        <el-col :span="8">
          <el-form-item label="用户层级　　" prop="level">
        <el-select v-model="form.level" placeholder="请选择用户层级">
          <el-option
            v-for="item in levelList"
            :label="item.name"
            :key="item.levelId"
            :value="item.levelId"
          ></el-option>
        </el-select>
      </el-form-item>
        </el-col>
      </el-row> -->

      <el-row>
        <el-col :span="8">
          <el-form-item label="单日提现金额" prop="dailyAmount">
            <el-input placeholder="请输入金额" v-model.number="form.dailyAmount" @keyup.enter.native="doSave({action: 'saveForm', form: 'strategyForm'})">
              <template slot="prepend">></template>
              <template slot="append">元</template>
            </el-input>
          </el-form-item>
        </el-col>
        <el-col :span="8">
          <el-form-item label="单次提现金额" prop="amount">
            <el-input placeholder="请输入金额" v-model.number="form.amount" @keyup.enter.native="doSave({action: 'saveForm', form: 'strategyForm'})">
              <template slot="prepend">>=</template>
              <template slot="append">元</template>
            </el-input>
          </el-form-item>
        </el-col>
      </el-row>
      <el-row>
        <el-col :span="8">
          <el-form-item label="当日提现次数" prop="dailyTimes">
            <el-input placeholder="请输入次数" v-model.number="form.dailyTimes" @keyup.enter.native="doSave({action: 'saveForm', form: 'strategyForm'})">
              <template slot="prepend">></template>
              <template slot="append">次</template>
            </el-input>
          </el-form-item>
        </el-col>
      </el-row>
      <el-row>
        <el-col :span="8">
          <el-form-item label="首次提现金额" prop="firstAmount">
            <el-input placeholder="请输入金额" v-model.number="form.firstAmount" @keyup.enter.native="doSave({action: 'saveForm', form: 'strategyForm'})">
              <template slot="prepend">></template>
              <template slot="append">元</template>
            </el-input>
          </el-form-item>
        </el-col>
      </el-row>
      <el-row>
        <el-col :span="8">
          <el-form-item label="当日盈利金额" prop="dailyProfit">
            <el-input placeholder="请输入金额" v-model.number="form.dailyProfit" @keyup.enter.native="doSave({action: 'saveForm', form: 'strategyForm'})">
              <template slot="prepend">></template>
              <template slot="append">元</template>
            </el-input>
          </el-form-item>
        </el-col>
      </el-row>
      <el-row>
        <el-col :span="8">
          <el-form-item label="7日累计提现金额" prop="weeklyAmount">
            <el-input placeholder="请输入金额" v-model.number="form.weeklyAmount" @keyup.enter.native="doSave({action: 'saveForm', form: 'strategyForm'})">
              <template slot="prepend">></template>
              <template slot="append">元</template>
            </el-input>
          </el-form-item>
        </el-col>
      </el-row>
      <el-row>
        <el-col :span="8">
          <el-form-item label="同IP多账号检测" prop="sameIpCheck">
            <el-radio-group v-model="form.sameIpCheck" size="medium">
              <el-radio-button :label="1" value="1">开启</el-radio-button>
              <el-radio-button :label="2" value="2">关闭</el-radio-button>
            </el-radio-group>
          </el-form-item>
        </el-col>
        <el-col :span="8">
          <el-form-item label="同设备多账号检测" prop="sameDeviceCheck">
            <el-radio-group v-model="form.sameDeviceCheck" size="medium">
              <el-radio-button :label="1" value="1">开启</el-radio-button>
              <el-radio-button :label="2" value="2">关闭</el-radio-button>
            </el-radio-group>
          </el-form-item>
        </el-col>
      </el-row>
    </el-form>

     <el-button v-if="roleCheck('withdraw-risk-config-btn')" class="filter-item" type="primary"  @click="doSave({action: 'saveForm', form: 'strategyForm'})">保存
      </el-button>
      <el-button v-if="roleCheck('withdraw-risk-config-btn')" @click="selfResetForm('strategyForm')">重置</el-button>
  </div>

</template>

<script>
import { form, factory } from "@/build";
import { updateStrategyConfigs, getStrategyConfigs } from "@/services/api/strategy";
import { getUserLevelList } from "@/services/api/userLevel";
export default {
  name: "strategy-setting-dialog",
  mixins: [form, factory],
  data() {
    return {
      levelList: [],
      form: {},
      strategyRule: {
        dailyAmount: factory.getRule("money"),
        amount: factory.getRule("money"),
        firstAmount: factory.getRule("money"),
        dailyProfit: factory.getRule("money"),
        weeklyAmount: factory.getRule("money"),
        level: [{ required: true, message: "层级选择不能为空" }],
        dailyTimes: [
          { required: true, message: "单日提现次数不能为空" },
          { validator: factory.getValidator("nonNegativeInteger") }
        ],
        continuousMinutes: [
          { required: true, message: "连续提现时间配置不能为空" },
          { validator: factory.getValidator("nonNegativeInteger") }
        ],
        continuousWithdrawTimes: [
          { required: true, message: "连续提现次数不能为空" },
          { validator: factory.getValidator("nonNegativeInteger") }
        ],
        sameIpCheck: [
          {
            required: true,
            message: "同IP多账号检测为必选项",
            trigger: "change"
          }
        ],
        sameDeviceCheck: [
          {
            required: true,
            message: "同设备多账号检测为必选项",
            trigger: "change"
          }
        ]
      }
    };
  },
  methods: {
    cancel() {
      this.$emit("input", false);
    }
  },
  mounted() {
    this.bindSave(updateStrategyConfigs, "saveForm", "form", {
      afterSuccess: () => {
        // this.resetForm("strategyForm");
        this.$parent.getAll();
        this.cancel();
      }
    });
    this.bindGet(getStrategyConfigs, "form", {
      format: data => {
        return  data || {
          sameDeviceCheck: 2,
          sameIpCheck: 2,
        };
      }
    });
    this.getAll();
  }
};
</script>

<style lang="scss" scoped>
  .tips{
    color: #ccc;
  }
</style>
